import React from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Card, Space, Button, Tabs, Row, Col, Table } from 'antd';

import MfgPlanUpdate from './MfgPlanUpdate';
class ViewPage extends React.Component<any, any> {
  constructor(props: any) {
    super(props)
    this.state = {

    }
  }
  query = () => [

  ]
  /**
   * 控制新增，编辑事件
   */
  handleSubmit = async (values: any) => {
    const { editStatus } = this.state;
    // const { dispatch } = this.props;
    if (editStatus) {
      // await dispatch({
      //   type: '#/edit',
      //   payload,
      // });
    } else {
      // await dispatch({
      //   type: '#/add',
      //   payload,
      // });
    }
    this.switchVisible();
    this.query();
  };

  /**
   * 控制更新模态框显示
   * @param {boolean} visible 是否显示
   * @param {object} formVals 模态框默认值
   * @param {boolean} editStatus 是否编辑模式
   */
  switchVisible = (visible = false, formVals = {}, editStatus = false) => {
    let newFormVals = {};
    // if (formVals) {
    //   for (let key in formVals) {
    //     newFormVals[key.toLocaleLowerCase()] = formVals[key];
    //   }
    //   newFormVals = momentAll(newFormVals);
    // }
    this.setState({
      visible,
      formVals,
      // formVals: newFormVals,
      editStatus,
    });
  };
  render() {
    const columns = [
      {
        title: '序号',
        key: 'id',
        render: (_: any, __: any, i: any) => i + 1,
      },
      {
        title: '产品编码',
        dataIndex: 'productId',
      },
      {
        title: '物料',
        dataIndex: 'supplier',
      },
      {
        title: '数量',
        dataIndex: 'count',
      },
      {
        title: '仓库',
        dataIndex: 'workHouse',
      },
    ];
    const list = [
      {
        productId: '2021062801',
        supplier: '纤维',
        workHouse: '物料仓',
        count: '19',
      },
    ];

    const { visible, formVals, editStatus } = this.state;
    return (
      <PageHeaderWrapper title={false}>
        <Card title="生产计划" extra={
          <Space>
            <Button type="primary" onClick={() => this.switchVisible(true)}>新增</Button>
          </Space>
        }>
          <Table rowKey="id" columns={columns} dataSource={list} />
        </Card>
        <MfgPlanUpdate
          visible={visible}
          onCancel={this.switchVisible}
          onSubmit={this.handleSubmit}
        />
      </PageHeaderWrapper>
    );
  }
}
export default ViewPage;
